﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Web.Mvc {
    public static class ImageExtensions {


        #region Image


        /// <summary>
        /// A Simple image
        /// </summary>
        /// <param name="imageRelativeUrl">The url for the image</param>
        /// <returns></returns>
        public static string Image(this HtmlHelper helper, string imageRelativeUrl) {
            return Image(helper, imageRelativeUrl, "", null);
        }

        /// <summary>
        /// A Simple image
        /// </summary>
        /// <param name="imageRelativeUrl">The url for the image</param>
        /// <param name="htmlName">ID of the Image (for use with javascript)</param>
        /// <returns></returns>
        public static string Image(this HtmlHelper helper, string imageRelativeUrl, string htmlName) {
            return Image(helper, imageRelativeUrl, htmlName, null);
        }

        /// <summary>
        /// A Simple image
        /// </summary>
        /// <param name="imageRelativeUrl">The url for the image</param>
        /// <param name="htmlName">ID of the Image (for use with javascript)</param>
        /// <param name="htmlAttributes">Any attributes you want set on the tag. Use anonymous-type declaration for this: new{class=cssclass}</param>
        /// <returns></returns>
        public static string Image(this HtmlHelper helper, string imageRelativeUrl, string htmlName, object htmlAttributes) {
            string buttonFormat = "<img name=\"{0}\" id=\"{0}\" src=\"{1}\" {2} />" ;

            //see if we can find the image
            IHttpContext ctx = helper.ViewContext.HttpContext;

            string resolvedUrl = LinkExtensions.ResolveUrl(helper, imageRelativeUrl);


            string atts = string.Empty;
            if (htmlAttributes != null)
                atts = htmlAttributes.ToAttributeList();

            return string.Format(buttonFormat, htmlName, resolvedUrl, atts);
        }
        #endregion


    }
}
